using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication11.Models.Mapping
{
    public class medicineMap : EntityTypeConfiguration<medicine>
    {
        public medicineMap()
        {
            // Primary Key
            this.HasKey(t => t.medicine_id);

            // Properties
            this.Property(t => t.medicine_name)
                .IsRequired()
                .HasMaxLength(32);

            this.Property(t => t.usage_type)
                .HasMaxLength(80);

            this.Property(t => t.dosage)
                .HasMaxLength(200);

            this.Property(t => t.usage)
                .HasMaxLength(200);

            this.Property(t => t.frequency)
                .HasMaxLength(50);

            this.Property(t => t.bad_consequence)
                .HasMaxLength(80);

            this.Property(t => t.effect_time)
                .HasMaxLength(50);

            this.Property(t => t.persistence_time)
                .HasMaxLength(50);

            this.Property(t => t.description)
                .HasMaxLength(200);

            this.Property(t => t.medicine_name_en_US)
                .IsRequired()
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("medicine");
            this.Property(t => t.medicine_id).HasColumnName("medicine_id");
            this.Property(t => t.medicine_name).HasColumnName("medicine_name");
            this.Property(t => t.drug_type_id).HasColumnName("drug_type_id");
            this.Property(t => t.usage_type).HasColumnName("usage_type");
            this.Property(t => t.dosage).HasColumnName("dosage");
            this.Property(t => t.usage).HasColumnName("usage");
            this.Property(t => t.frequency).HasColumnName("frequency");
            this.Property(t => t.bad_consequence).HasColumnName("bad_consequence");
            this.Property(t => t.effect_time).HasColumnName("effect_time");
            this.Property(t => t.persistence_time).HasColumnName("persistence_time");
            this.Property(t => t.description).HasColumnName("description");
            this.Property(t => t.medicine_name_en_US).HasColumnName("medicine_name!en-US");

            // Relationships
            this.HasRequired(t => t.drug_type)
                .WithMany(t => t.medicines)
                .HasForeignKey(d => d.drug_type_id);

        }
    }
}
